package service.Impl;

import dao.Impl.DishDaoImpl;
import dao.Impl.SetmealDaoImpl;
import model.DTO.DishEditDTO;
import model.DTO.DishPageDTO;
import model.VO.DishAndSetmealVO;
import model.VO.DishPageVO;
import model.VO.DishVO;
import model.entity.Dish;
import model.entity.Setmeal;
import service.DishService;

import java.util.List;

public class DishServiceImpl implements DishService {
    DishDaoImpl dish=new DishDaoImpl();
    @Override
    public void edit(DishEditDTO d) {
        dish.edit(d);
    }

    @Override
    public void del(String ids) {
        dish.del(ids);
    }

    @Override
    public void add(int categoryId, String image, String name, double price, String description, int id, int status) {
        status=1;
        dish.add(categoryId,image,name,price,description,id,status);
    }

    @Override
    public DishVO find(int id) {
        return dish.find(id);
    }

    @Override
    public List<Dish> getCateDishes(int categoryId) {
        List<Dish> dishList;
        dishList=dish.getCateDishes(categoryId);
        return dishList;
    }

    @Override
    public DishPageVO pageQuery(DishPageDTO dishPageDTO) {
        DishPageVO dishPageVO=new DishPageVO();
        List<DishVO> records=dish.Page(dishPageDTO);
        dishPageVO.setTotal(dish.count(dishPageDTO));
        dishPageVO.setrecords(records);
        return dishPageVO;
    }

    @Override
    public void statusEdit(int id) {
        dish.statusEdit(id);
    }

    @Override
    public DishAndSetmealVO findDishAndSetmeal(String name) {
        SetmealDaoImpl setmealDao = new SetmealDaoImpl();
        DishAndSetmealVO dishAndSetmealVO = new DishAndSetmealVO();
        List<Dish> dishList=dish.list(name);
        List<Setmeal> setmealList=setmealDao.list(name);
        dishAndSetmealVO.setDishList(dishList);
        dishAndSetmealVO.setSetmealList(setmealList);
        return dishAndSetmealVO;
    }
}
